package Server.Jsmj.RGCP.QILE;

public class JiangUtil {

	public static int[] laoJiang = { 27, 28, 29 };
	public static int[] touweiJiang = { 0, 8, 9, 17, 18, 26 };

	/**
	 * ��ȡ����
	 * 
	 * @param fanJiang
	 * @param Jiang
	 * @param pengPai
	 * @return
	 */
	public static int getPengScore(int fanJiang, int[] Jiang, int pengPai) {
		int ret = 0;
		if(is_laoJiang(fanJiang)){
			if(pengPai == fanJiang){
				ret = 16;
			}else if(is_laoJiang(pengPai)){
				ret = 8;
			}else if(is_jiang(pengPai, Jiang)){
				ret = 4;
			}else{
				ret = 1;
			}
		}else{
			if(pengPai == fanJiang){
				ret = 8;
			}else if(is_jiang(pengPai, Jiang)){
				ret = 4;
			}else{
				ret = 1;
			}
		}
		return ret;
	}

	/**
	 * ��ȡ���̷�
	 * 
	 * @param fanJiang
	 * @param Jiang
	 * @param pengPai
	 * @return
	 */
	public static int getAnKeScore(int fanJiang, int[] Jiang, int ankePai) {
		int ret = 0;
		if(is_laoJiang(fanJiang)){
			if(ankePai == fanJiang){
				ret = 48;
			}else if(is_laoJiang(ankePai)){
				ret = 16;
			}else if(is_jiang(ankePai, Jiang)){
				ret = 8;
			}else{
				ret = 2;
			}
		}else{
			if(ankePai == fanJiang){
				ret = 24;
			}else if(is_jiang(ankePai, Jiang)){
				ret = 8;
			}else{
				ret = 2;
			}
		}
		return ret;
	}

	/**
	 * ��ȡ���ܷ�
	 * 
	 * @param fanJiang
	 * @param Jiang
	 * @param minggangPai
	 * @return
	 */
	public static int getMingGangScore(int fanJiang, int[] Jiang, int minggangPai) {
		int ret = 0;
		if (is_jiang(minggangPai, Jiang)) {
			if (is_laoJiang(fanJiang) && is_laoJiang(minggangPai)) {
				ret = 32;
			} else {
				ret = 16;
			}
		} else {
			ret = 4;
		}
		return ret;
	}

	/**
	 * ��ȡ���ܷ�
	 * 
	 * @param fanJiang
	 * @param Jiang
	 * @param minggangPai
	 * @return
	 */
	public static int getAnGangScore(int fanJiang, int[] Jiang, int angangPai) {
		int ret = 0;
		if (is_jiang(angangPai, Jiang)) {
			if (is_laoJiang(fanJiang) && is_laoJiang(angangPai)) {
				ret = 48;
			} else {
				ret = 24;
			}
		} else {
			ret = 6;
		}
		return ret;
	}
	
	/**
	 * ��ȡ����
	 * 
	 * @param fanJiang
	 * @param Jiang
	 * @param minggangPai
	 * @return
	 */
	public static int getLongScore(int fanJiang, int[] Jiang, int longPai) {
		int ret = 0;
		if(is_laoJiang(fanJiang)){
			if(longPai == fanJiang){
				ret = 64;
			}else if(is_laoJiang(longPai)){
				ret = 64;
			}else if(is_jiang(longPai, Jiang)){
				ret = 32;
			}else{
				ret = 8;
			}
		}else{
			if(longPai == fanJiang){
				ret = 32;
			}else if(is_jiang(longPai, Jiang)){
				ret = 32;
			}else{
				ret = 8;
			}
		}
		return ret;
	}

	/**
	 * �ж�һ�����Ƿ���
	 * 
	 * @param pai
	 * @param Jiang
	 * @return
	 */
	public static boolean is_jiang(int pai, int[] Jiang) {
		for (int i = 0; i < Jiang.length; i++) {
			if (Jiang[i] == pai) {
				return true;
			}
		}
		return false;
	}

	/**
	 * �ж�һ�����Ƿ���ͷβ��
	 * 
	 * @param pai
	 * @return
	 */
	public static boolean is_touweiJiang(int pai) {
		for (int i = 0; i < touweiJiang.length; i++) {
			if (touweiJiang[i] == pai) {
				return true;
			}
		}
		return false;
	}

	/**
	 * �ж�һ�����Ƿ��Ͻ�
	 * 
	 * @param pai
	 * @return
	 */
	public static boolean is_laoJiang(int pai) {
		for (int i = 0; i < laoJiang.length; i++) {
			if (laoJiang[i] == pai) {
				return true;
			}
		}
		return false;
	}

	/**
	 * �ж�һ�����Ƿ񷭽�
	 * 
	 * @param fanJiang
	 * @param pai
	 * @return
	 */
	public static int[] getJiang(int fanJiang) {
		// ������ϲ�� 147�Ľ�
		if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
//			int[] jiang = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
//					25, 26, 27, 28, 29 };
//			return jiang;
			int[] jiang = { 0, 3, 6, 8, 9, 12, 15, 17, 18, 21, 24, 26, 27, 28, 29 };
			return jiang;
		}
		// �����Ǻ컨 �� 258
		if (fanJiang == 27 || fanJiang == 1 || fanJiang == 4 || fanJiang == 7 || fanJiang == 10 || fanJiang == 13
				|| fanJiang == 16 || fanJiang == 19 || fanJiang == 22 || fanJiang == 25) {
			int[] jiang = { 0, 1, 4, 7, 8, 9, 10, 13, 16, 17, 18, 19, 22, 25, 26, 27, 28, 29 };
			return jiang;
		}
		// ������ǧ�� ��147
		if (fanJiang == 28 || fanJiang == 0 || fanJiang == 3 || fanJiang == 6 || fanJiang == 9 || fanJiang == 12
				|| fanJiang == 15 || fanJiang == 18 || fanJiang == 21 || fanJiang == 24) {
			int[] jiang = { 0, 3, 6, 8, 9, 12, 15, 17, 18, 21, 24, 26, 27, 28, 29 };
			return jiang;
		}
		// �����ǰ׻� ��369
		if (fanJiang == 29 || fanJiang == 2 || fanJiang == 5 || fanJiang == 8 || fanJiang == 11 || fanJiang == 14
				|| fanJiang == 17 || fanJiang == 20 || fanJiang == 23 || fanJiang == 26) {
			int[] jiang = { 0, 2, 5, 8, 9, 11, 14, 17, 18, 20, 23, 26, 27, 28, 29 };
			return jiang;
		}
		return null;
	}
	
	public static void main(String[] args) {
		int fanJiang = 2;
		int[] Jiang = getJiang(fanJiang);
		System.out.println(Jiang.length);
	}

}
